<!--
 * @Author: 杨伟韦
 * @Date: 2025-05-25 15:30:21
 * @LastEditors: 杨伟韦
-->
<template>
  <div class="menus">
    <div :class="`left-bar ${state.toolsBarShow && 'show-tools-bar'}`">
      <div class="left-bar-wrapper">
        <!-- LOGO -->
        <!-- <img :src="logo" /> -->
        <Icon class="left-logo" type="logo-instagram" size="40" />
        <!-- 左侧菜单 -->
        <ul class="left-bar-menu">
          <template v-for="item in leftBar" :key="item.key">
            <li
              :class="`menu-item ${state.menuActive === item.key && 'active'}`"
              :name="item.key"
              @click="handleClickMenu(item.key)"
            >
              <Icon
                v-if="state.menuActive === item.key"
                :type="item.selectIcon"
                size="24"
                class="menu-icon"
              />
              <Icon v-else :type="item.icon" size="24" color="#666" />
            </li>
            <div :class="`menu-name ${state.menuActive === item.key && 'active'}`">
              {{ item.name }}
            </div>
          </template>
        </ul>
        <!-- 日夜模式 -->
        <div class="left-mode" @click="handleClickTheme()"></div>
      </div>
    </div>
  </div>
</template>

<script name="menus" setup>
// 左侧组件
import { useI18n } from 'vue-i18n';
import logo from '@/assets/images/logo/logo.png';

const { t } = useI18n();

const state = reactive({
  menuActive: 'importTmpl',
  toolsBarShow: true,
  isDarkTheme: false,
});

// fix: 修复vue-i18n function "t" not reactive inside ref object
// https://github.com/intlify/vue-i18n/issues/1396#issuecomment-1716123143
const leftBar = reactive([
  {
    //模板
    key: 'importTmpl',
    name: '首页', //computed(() => t('templates')),
    icon: 'ios-home-outline',
    selectIcon: 'ios-home',
  },
  {
    // 用户素材
    key: 'notifytion',
    name: '通知', //computed(() => t('mine')),
    icon: 'ios-notifications-outline',
    selectIcon: 'ios-notifications',
  },
  {
    // 用户素材
    key: 'myMaterial',
    name: '我的', //computed(() => t('mine')),
    icon: 'ios-person-outline',
    selectIcon: 'ios-person',
  },
]);

const handleClickMenu = (key) => {
  state.menuActive = key;
};

const handleClickTheme = () => {
  const body = document.body;
  if (!state.isDarkTheme) {
    body.classList.add('theme-dark'); // 添加深色主题类
  } else {
    body.classList.remove('theme-dark'); // 移除深色主题类，回到默认主题
  }
  state.isDarkTheme = !state.isDarkTheme;
};
</script>
<style lang="less" scoped>
.left-bar {
  width: 80px;
  height: 100%;
  background: var(--background-primary-color);
  display: flex;
  position: relative;
  border-right: 1px solid #f2f2f2;

  .left-bar-wrapper {
    border-radius: 2px;
    overflow: hidden;
    width: 80px;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    align-items: center;

    .left-logo {
      height: 60px;
      line-height: 60px;
      text-align: center;
      border-radius: 2px;
      margin-bottom: 50px;

      font-size: 20px;
      font-weight: 500;
      color: var(--primary-color);
    }

    .left-bar-menu {
      flex: 1;

      .menu-item {
        width: 40px;
        height: 40px;
        border-radius: 8px;
        cursor: pointer;
        display: flex;
        align-items: center;
        justify-content: center;
        transition: all 0.3s ease;

        &.active {
          background-color: rgba(0, 0, 0, 0.05);

          .menu-icon {
            color: var(--primary-color);
          }
        }
      }

      .menu-name {
        margin-top: 6px;
        margin-bottom: 30px;
        font-size: 12px;
        text-align: center;
        color: #666;

        &.active {
          color: var(--primary-color);
          font-weight: bold;
        }
      }
    }

    .left-mode {
      width: 30px;
      height: 60px;
      border-radius: 15px;
      background-color: var(--secondary-color);
      margin-bottom: 20px;
      cursor: pointer;
    }
  }
}
</style>
